package com.yp.demo.web;

import com.yp.demo.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by CrazyMouse on 2017/7/19.
 */
@RestController
public class UserController {

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/user")
    @PreAuthorize("hasAnyAuthority({'user'})")
    public Object getUser() {
        return userFeign.getUser();
    }

    @GetMapping("/")
    public String index(HttpServletResponse response) {
//        try {
//            //替换成第三方首页地址
//            response.sendRedirect("http://localhost:3000");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        return "授权成功!!!";
    }
}
